package com.supermap.dubbo.api.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * @author yuyao
 * @ClassName: ResponseData
 * @Description: 返回参数实体类
 * @date 2017年12月28日 下午5:59:40
 */
public class IotResponseData {

    /**
     * 返回表示 0 成功 默认成功
     */
    private int code;
    /**
     * 返回信息
     */
    private String msg;
    /**
     * 返回数据
     */
    private Object data;
    /**
     * 最新数据时间
     */
    private String time;

    public IotResponseData() {
        this.code = 200;
    }

    public IotResponseData(int code, Object data) {
        this.code = code;
        this.data = data;
        if (code == 404) {
            msg = "SERVICE GET AN EXCEPTION";
        } else {
            msg = "SERVICE GET SUCCESS";
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public JSONObject toFastJson() {
        JSONObject json = new JSONObject();
        json.put("code", this.code);
        json.put("msg", this.msg);
        json.put("data", JSON.toJSON(this.data));
        json.put("time", this.time);
        return json;
    }
}
